home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17378 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  53 lines

  1. Path: news.sprintlink.net!datalytics!usenet
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: A class with pointers to yet undeclared classes
  5. Date: Mon, 15 Apr 1996 13:09:32 -0400
  6. Organization: Datalytics, Inc
  7. Message-ID: <317282CC.5A18@datalytics.com>
  8. References: <4ksden$276@decaxp.HARVARD.EDU>
  9. NNTP-Posting-Host: 204.62.224.71
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. Mark Mueller wrote:
  16. > How do I convince the compiler that class B is going to be declared later?
  17. >   Mark
  18. >   mueller@fas.harvard.edu
  19.  
  20. A.h (or hpp, or hxx, etc.):
  21.  
  22. class B;
  23.  
  24. class A
  25. {
  26.    B* m_pB;
  27. };
  28.  
  29. A.cpp (or cxx, or C, or c++, etc.):
  30.  
  31. #include <B.h>
  32. #include <A.h>
  33.  
  34. .
  35. .
  36. .
  37.  
  38. As you can see, you've told the compiler that B is a class, and 
  39. so long as m_pB (in this case) is a pointer or reference to B, 
  40. and you don't use it in any inline member functions, you're all 
  41. set.
  42.  
  43. This is a standard approach to reduce compilation times: by 
  44. forward declaring classes, rather than including the class' 
  45. header, you reduce the code that must be processed in the 
  46. current translation unit.
  47.  
  48. -- 
  49. Robert Stewart        | My opinions are usually my own.
  50. Datalytics, Inc.    | stew@datalytics.com
  51.